<template>
  <BasicModal
    :title="title"
    :width="width"
    :open="open"
    :height="600"
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <OneNativeForm ref="realForm" @ok="submitCallback" :disabled="disableSubmit" />
  </BasicModal>
</template>

<script lang="ts" setup>
  import { ref, nextTick } from "vue"
  import OneNativeForm from "./OneNativeForm.vue"
  import { BasicModal } from "/@/components/Modal"

  const title = ref<string>("")
  const width = ref<number>(800)
  const open = ref<boolean>(false)
  const disableSubmit = ref<boolean>(false)
  const realForm = ref()
  const emit = defineEmits(["register", "ok"])

  function add() {
    title.value = "新增"
    open.value = true
    nextTick(() => {
      realForm.value.add()
    })
  }

  function edit(record) {
    title.value = disableSubmit.value ? "详情" : "编辑"
    open.value = true
    nextTick(() => {
      realForm.value.edit(record)
    })
  }

  function handleOk() {
    realForm.value.submitForm()
  }

  function submitCallback() {
    handleCancel()
    emit("ok")
  }

  function handleCancel() {
    open.value = false
  }

  defineExpose({
    add,
    edit,
    disableSubmit,
  })
</script>

<style lang="less" scoped></style>
